home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 80 / XENIATGM80.iso / Goodies / Blood 2 / Source / data.z / MenuBase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-02  |  10.1 KB  |  231 lines

  1. // MenuBase.h: interface for the CMenuBase class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #if !defined(AFX_MENUBASE_H__D7668B31_57D4_11D2_BDA0_0060971BDC6D__INCLUDED_)
  6. #define AFX_MENUBASE_H__D7668B31_57D4_11D2_BDA0_0060971BDC6D__INCLUDED_
  7.  
  8. #if _MSC_VER >= 1000
  9. #pragma once
  10. #endif // _MSC_VER >= 1000
  11.  
  12. #include "LTGUIMgr.h"
  13. #include "stdlith.h"
  14.  
  15. class CMainMenus;
  16. class CLTGUIFadeItemCtrl;
  17. class CLTGUITextItemCtrl;
  18. class CMenuBase : public CLTGUICommandHandler
  19. {
  20. public:
  21.     CMenuBase();
  22.     virtual ~CMenuBase();
  23.  
  24.     // Initialization/Termination
  25.     virtual    DBOOL    Init(CClientDE *pClientDE, CMainMenus *pMainMenus,
  26.                          CMenuBase *pParentMenu, DWORD dwMenuID, int nMenuHeight);
  27.     virtual void    Term();
  28.  
  29.     // Builds the menu
  30.     virtual void    Build()                                { m_bBuilt=DTRUE; }
  31.     DBOOL            IsBuilt()                            { return m_bBuilt; }
  32.  
  33.     // Get the parent menu
  34.     CMenuBase        *GetParentMenu()                    { return m_pParentMenu; }
  35.  
  36.     // Get the background of the menu
  37.     char            *GetBackground()                    { return m_szBackground; }
  38.  
  39.     // Get the main menus class
  40.     CMainMenus        *GetMainMenus()                        { return m_pMainMenus; }
  41.  
  42.     // Get the menu ID
  43.     DDWORD            GetMenuID()                            { return m_dwMenuID; }
  44.  
  45.     // Renders the menu to a surface
  46.     virtual void    Render(HSURFACE hDestSurf);
  47.  
  48.     // Creates the title for the menu from the path to the image.  The non-Enlish version
  49.     // overwrites the surface with a text string specified by the string ID.
  50.     DBOOL            CreateTitle(char *lpszTitleSurf, int nStringID, DIntPt titlePos);
  51.  
  52.     // This is called when the menu gets or loses focus
  53.     virtual void    OnFocus(DBOOL bFocus)                { }
  54.  
  55.     /////////////////////////////////////////
  56.     // Adds a menu options using an HSTRING
  57.     CLTGUIFadeItemCtrl        *AddFadeItemOption(char *lpszOptionSurfPrefix, int nSurfaces, HSTRING hOptionText, DWORD dwCommandID, int xPos=-1, int yPos=-1);
  58.     CLTGUITextItemCtrl        *AddTextItemOption(HSTRING hText, DWORD dwCommandID, CLTGUIFont *pFontArray, int nNumFonts=1, DBOOL bDrawSolid=DTRUE, int *pnValue=DNULL);
  59.     CLTGUIColumnTextCtrl    *AddColumnTextOption(DWORD dwCommandID, CLTGUIFont *pFont);
  60.     CLTGUISliderCtrl        *AddSliderOption(HSTRING hText, CLTGUIFont *pFont, int nSliderOffset, HSURFACE hBarSurf, HSURFACE hTabSurf, int *pnValue=DNULL);
  61.     CLTGUIOnOffCtrl            *AddOnOffOption(HSTRING hText, CLTGUIFont *pFont, int nRightColumnOffset, DBOOL *pbValue=DNULL);
  62.     CLTGUIEditCtrl            *AddEditOption(HSTRING hDescription, DWORD dwCommandID, CLTGUIFont *pFont, int nEditStringOffset, int nBufferSize, char *lpszValue=DNULL);
  63.  
  64.     // Just a wrapper for adding fading text options with large fonts
  65.     CLTGUITextItemCtrl        *AddLargeTextItemOption(HSTRING hText, DWORD dwCommandID);    
  66.  
  67.     ///////////////////////////////////////////////////////////////////////////////////
  68.     // Wrappers for adding menu items with a resource string ID instead of an HSTRING
  69.     CLTGUIFadeItemCtrl        *AddFadeItemOption(char *lpszOptionSurfPrefix, int nSurfaces, int messageCode, DWORD dwCommandID, int xPos=-1, int yPos=-1);
  70.     CLTGUITextItemCtrl        *AddTextItemOption(int messageCode, DWORD dwCommandID, CLTGUIFont *pFontArray, int nNumFonts=1, DBOOL bDrawSolid=DTRUE, int *pnValue=DNULL);    
  71.     CLTGUISliderCtrl        *AddSliderOption(int messageCode, CLTGUIFont *pFont, int nSliderOffset, HSURFACE hBarSurf, HSURFACE hTabSurf, int *pnValue=DNULL);
  72.     CLTGUIOnOffCtrl            *AddOnOffOption(int messageCode, CLTGUIFont *pFont, int nRightColumnOffset, DBOOL *pbValue=DNULL);
  73.     CLTGUIEditCtrl            *AddEditOption(int messageCode, DWORD dwCommandID, CLTGUIFont *pFont, int nEditStringOffset, int nBufferSize, char *lpszValue=DNULL);    
  74.     CLTGUITextItemCtrl        *AddLargeTextItemOption(int messageCode, DWORD dwCommandID);    
  75.  
  76.     ///////////////////////////////////////////////////////////////////////////////////
  77.     // Wrappers for adding menu items with a char* instead of a string ID or HSTRING
  78.     inline CLTGUIFadeItemCtrl    *AddFadeItemOption(char *lpszOptionSurfPrefix, int nSurfaces, char *lpszOptionText, DWORD dwCommandID, int xPos=-1, int yPos=-1);
  79.     inline CLTGUITextItemCtrl    *AddTextItemOption(char *lpszText, DWORD dwCommandID, CLTGUIFont *pFontArray, int nNumFonts=1, DBOOL bDrawSolid=DTRUE, int *pnValue=DNULL);    
  80.     inline CLTGUISliderCtrl        *AddSliderOption(char *lpszText, CLTGUIFont *pFont, int nSliderOffset, HSURFACE hBarSurf, HSURFACE hTabSurf, int *pnValue=DNULL);
  81.     inline CLTGUIOnOffCtrl        *AddOnOffOption(char *lpszText, CLTGUIFont *pFont, int nRightColumnOffset, DBOOL *pbValue=DNULL);
  82.     inline CLTGUIEditCtrl        *AddEditOption(char *lpszDescription, DWORD dwCommandID, CLTGUIFont *pFont, int nEditStringOffset, int nBufferSize, char *lpszValue=DNULL);
  83.     inline CLTGUITextItemCtrl    *AddLargeTextItemOption(char *lspzText, DWORD dwCommandID);    
  84.  
  85.     // Sets the parent menu
  86.     void            SetParentMenu(CMenuBase *pParent)    { m_pParentMenu=pParent; }
  87.  
  88.     // Calls UpdateData on each control in the menu
  89.     void            UpdateData(DBOOL bSaveAndValidate=DTRUE);
  90.  
  91.     // Set the current menu item selection index.  Note that this will reset any animations.
  92.     void            SetCurrentItem ( int nItemIndex );
  93.  
  94.     // Gets the currently selected item
  95.     int                GetCurrentItemIndex()                { return m_listOption.GetSelectedItem(); }
  96.     CLTGUICtrl        *GetCurrentItem();
  97.  
  98.     // Sets the position of the title and menu option
  99.     void            SetTitlePos(int x, int y)            { m_titlePos.x=x; m_titlePos.y=y; }
  100.     void            SetTitlePos(DIntPt pt)                { SetTitlePos(pt.x, pt.y); }
  101.     void            SetOptionPos(int x, int y)            { m_listOption.SetPos(x, y); }
  102.     void            SetOptionPos(DIntPt pt)                { SetOptionPos(pt.x, pt.y); }
  103.  
  104.     // Sets the height of the menu
  105.     void            SetMenuHeight(int nHeight)            { m_listOption.SetHeight(nHeight); }
  106.  
  107.     // Turns on and off low resolution fonts for the menus
  108.     void            SetLowResolutionFonts(DBOOL bLowRes);
  109.  
  110.     // Sets the item spacing
  111.     void            SetItemSpacing(int nSpacing)        { m_listOption.SetItemSpacing(nSpacing); }
  112.  
  113.     // Sets whether or not the items should wrap when scrolling
  114.     void            SetScrollWrap(DBOOL bWrap)            { m_listOption.SetScrollWrap(bWrap); }
  115.  
  116.     // Turns the up/down arrows on/off and sets the X position that they should be pointing
  117.     void            UseArrows(DBOOL bUse, int xCenter);
  118.  
  119.     // Handles a key press.  Returns FALSE if the key was not processed through this method.
  120.     // Left, Up, Down, Right, and Enter are automatically passed through OnUp(), OnDown(), etc.
  121.     virtual    DBOOL    HandleKeyDown(int key, int rep);
  122.  
  123.     // Handle a device tracking message.
  124.     // Return DTRUE if the device tracking should stop.
  125.     virtual DBOOL    HandleDeviceTrack(DeviceInput *pInput, DDWORD dwNumDevices);
  126.  
  127. protected:
  128.     virtual DDWORD    OnCommand(DDWORD dwCommand, DDWORD dwParam1, DDWORD dwParam2);
  129.  
  130.     // Handle input
  131.     virtual void    OnUp();
  132.     virtual void    OnDown();
  133.     virtual void    OnLeft();
  134.     virtual void    OnRight();
  135.     virtual void    OnEnter();    
  136.  
  137.     // Removes all of the options from the menu
  138.     void        RemoveAllOptions();
  139.  
  140.     // Sorts a file list.  This was taken from the old menu code.
  141.     FileEntry*    SortFileList(FileEntry *pfe);
  142.  
  143.     // Renders the up/down arrows
  144.     void        RenderArrows(HSURFACE hDestSurf);
  145.  
  146. protected:
  147.     DBOOL            m_bInit;
  148.     DBOOL            m_bBuilt;
  149.  
  150.     CClientDE        *m_pClientDE;        // Client interface
  151.     CMainMenus        *m_pMainMenus;        // The main menus class
  152.  
  153.     DDWORD            m_dwMenuID;            // The ID of this menu
  154.     CMenuBase        *m_pParentMenu;        // The parent menu
  155.  
  156.     HSURFACE        m_hTitleSurf;        // The title surface
  157.     HSTRING            m_hTitleString;        // The title string
  158.  
  159.     DIntPt            m_titlePos;            // The title position
  160.     CLTGUIListCtrl    m_listOption;        // The list of menu items    
  161.  
  162.     char            *m_szBackground;    // The name of the file to use as the background
  163.     DBOOL            m_bBoxFormat;        // Should we format the list options in a box? or have free locations
  164.  
  165.     DBOOL            m_bShowArrows;        // TRUE if the up/down arrows should be drawn
  166.     int                m_nArrowCenter;        // The X coordinate of where the arrow center should be
  167.  
  168.     // Array of controls that this menu owns
  169.     CMoArray<CLTGUICtrl *>    m_controlArray;    
  170.  
  171.     // Stores controls added by AddLargeTextItemOption
  172.     CMoArray<CLTGUITextItemCtrl *>    m_largeFontItemArray;
  173. };
  174.  
  175. inline CLTGUIFadeItemCtrl *CMenuBase::AddFadeItemOption(char *lpszOptionSurfPrefix, int nSurfaces, char *lpszOptionText, DWORD dwCommandID, int xPos, int yPos)
  176. {
  177.     HSTRING hString=m_pClientDE->CreateString(lpszOptionText);
  178.     CLTGUIFadeItemCtrl *pCtrl=AddFadeItemOption(lpszOptionSurfPrefix, nSurfaces, hString, dwCommandID, xPos, yPos);
  179.     m_pClientDE->FreeString(hString);
  180.  
  181.     return pCtrl;
  182. }
  183.  
  184. inline CLTGUITextItemCtrl *CMenuBase::AddTextItemOption(char *lpszText, DWORD dwCommandID, CLTGUIFont *pFontArray, int nNumFonts, DBOOL bDrawSolid, int *pnValue)
  185. {
  186.     HSTRING hString=m_pClientDE->CreateString(lpszText);
  187.     CLTGUITextItemCtrl *pCtrl=AddTextItemOption(hString, dwCommandID, pFontArray, nNumFonts, bDrawSolid, pnValue);
  188.     m_pClientDE->FreeString(hString);
  189.  
  190.     return pCtrl;
  191. }
  192.  
  193.  
  194. inline CLTGUISliderCtrl *CMenuBase::AddSliderOption(char *lpszText, CLTGUIFont *pFont, int nSliderOffset, HSURFACE hBarSurf, HSURFACE hTabSurf, int *pnValue)
  195. {
  196.     HSTRING hString=m_pClientDE->CreateString(lpszText);
  197.     CLTGUISliderCtrl *pCtrl=AddSliderOption(hString, pFont, nSliderOffset, hBarSurf, hTabSurf, pnValue);
  198.     m_pClientDE->FreeString(hString);
  199.  
  200.     return pCtrl;
  201. }
  202.  
  203. inline CLTGUIOnOffCtrl *CMenuBase::AddOnOffOption(char *lpszText, CLTGUIFont *pFont, int nRightColumnOffset, DBOOL *pbValue)
  204. {
  205.     HSTRING hString=m_pClientDE->CreateString(lpszText);
  206.     CLTGUIOnOffCtrl *pCtrl=AddOnOffOption(hString, pFont, nRightColumnOffset, pbValue);
  207.     m_pClientDE->FreeString(hString);
  208.  
  209.     return pCtrl;
  210. }
  211.  
  212. inline CLTGUIEditCtrl *CMenuBase::AddEditOption(char *lpszDescription, DWORD dwCommandID, CLTGUIFont *pFont, int nEditStringOffset, int nBufferSize, char *lpszValue)
  213. {
  214.     HSTRING hString=m_pClientDE->CreateString(lpszDescription);
  215.     CLTGUIEditCtrl *pCtrl=AddEditOption(hString, dwCommandID, pFont, nEditStringOffset, nBufferSize, lpszValue);
  216.     m_pClientDE->FreeString(hString);
  217.  
  218.     return pCtrl;
  219. }
  220.  
  221. inline CLTGUITextItemCtrl *CMenuBase::AddLargeTextItemOption(char *lpszText, DWORD dwCommandID)
  222. {
  223.     HSTRING hString=m_pClientDE->CreateString(lpszText);
  224.     CLTGUITextItemCtrl *pCtrl=AddLargeTextItemOption(lpszText, dwCommandID);
  225.     m_pClientDE->FreeString(hString);
  226.  
  227.     return pCtrl;
  228. }
  229.  
  230. #endif // !defined(AFX_MENUBASE_H__D7668B31_57D4_11D2_BDA0_0060971BDC6D__INCLUDED_)
  231.